﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace Library.OrmEnterpriseEntity.TableInfo {
  public class OneItemCollection<T> : ICollection<T> where T : DbTable, new() {
    public T Item { get; set; }
    public IEnumerator<T> GetEnumerator() {
      throw new NotImplementedException();
    }

    IEnumerator IEnumerable.GetEnumerator() {
      return GetEnumerator();
    }

    public void Add(T item) {
      Item = item;
    }

    public void Clear() {
      Item = null;
    }

    public bool Contains(T item) {
      return item == Item;
    }

    public void CopyTo(T[] array, int arrayIndex) {

    }

    public bool Remove(T item) {
      if (item == Item) {
        Item = null;
        return true;
      }
      return false;
    }

    public int Count {
      get { return Item == null ? 0 : 1; }
    }

    public bool IsReadOnly {
      get { return false; }
    }
  }
}
